package com.example.my.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.my.R;
import com.example.my.bean.Exercise;

import java.util.ArrayList;
import java.util.List;

public class Tab2Fragment extends Fragment {

    private List<Exercise> exerciseList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_tab_2_layout, container, false);
         ListView listView = view.findViewById(R.id.list);

         initExercise();

        ExcerciseAdapter adapter = new ExcerciseAdapter(exerciseList, getContext());
        listView.setAdapter(adapter);

         return view;
    }
    private void initExercise(){
        Exercise exercise;
        exerciseList.clear();
        for (int i=0;i<20;i++)
        {
            exercise = new Exercise();
            exercise.id = 1;
            exercise.title = "第"+(i+1)+"章";
            exercise.color = i%4;
            exercise.url = "https://www.biqugetv.com/";
            exerciseList.add(exercise);
        }
    }
}
